package com.desire.utils;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;

/**
 * @author LittleDesire
 * @description
 * @date 2022-04-29 周五 9:45
 * @since 17
 */
public class DbUtils {
    private static SqlSessionFactory factory;

    public static SqlSessionFactory getInstance() {
        if (factory == null) {
            InputStream in = null;
            try {
                in = Resources.getResourceAsStream("mybatisConfig.xml");
            } catch (IOException e) {
                e.printStackTrace();
            }
            synchronized (DbUtils.class) {
                if (factory == null) {
                    factory = new SqlSessionFactoryBuilder().build(in);
                }
            }
        }
        return factory;
    }
}
